package powerdev.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.Session;

import powerdev.excepcion.DAOExcepcion;
import powerdev.modelo.Persona;
import powerdev.negocio.GestionLocal;

/**
 * Servlet implementation class RegistrarLocal
 */
@WebServlet("/RegistrarLocal")
public class RegistrarLocal extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarLocal() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		GestionLocal neg=new GestionLocal();
		
		String a=request.getParameter("txtLocal");
		String b=request.getParameter("txtDireccion");
		Integer c=Integer.parseInt(request.getParameter("cboDistrito"));
		String d=request.getParameter("txtDireGoo");
		String e=request.getParameter("txtTelefono");
		Integer f=Integer.parseInt(request.getParameter("txtCoPersona2"));
		
		
		try {
			HttpSession sesion = request.getSession();
			
			Persona p = (Persona)sesion.getAttribute("USUARIO_ACTUAL");
			
			neg.insertarLocal(a, b, d, e, c, p.getCo_Persona());
			
			request.setAttribute("MENSAJE", "Se registro correctamente.");
			
		} catch (DAOExcepcion e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			request.setAttribute("MENSAJE", e1.getMessage());
		}

		RequestDispatcher rd = request
				.getRequestDispatcher("RegistroLocal.jsp");
		rd.forward(request, response);
		
	}

}
